package OEScode;

import java.util.ArrayList;
import java.util.List;

public class Examination {
    private String name;
    private List<Observer> candidates;

    public Examination(String name) {
        this.name = name;
        this.candidates=new ArrayList<>();
    }

    public void addCandidate(Observer observer) {
        if (observer != null && !candidates.contains(observer)) {
            candidates.add(observer);
        }
    }

    public void removeCandidate(Observer observer) {
        candidates.remove(observer);
    }

    public void notifyCandidates(String message) {
        System.out.println("候考人组<"+name+">接收考试系统发送通知: " + message);
        for (Observer observer : candidates) {
            observer.notify(message);
        }
    }
}
